//
//  WaitingView.m
//  MessangerSkeleton
//
//  Created by User-23 on 4/27/14.
//  Copyright (c) 2014 IOTrainingCamp. All rights reserved.
//

#import "WaitingView.h"

@interface WaitingView()

@property (nonatomic) UIImageView *loadingImageView;

@end

@implementation WaitingView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //message
        CGRect frame = [self bounds];
        
        UIImageView* background = [[UIImageView alloc] initWithFrame:frame];
        [background setImage:[UIImage imageNamed:@"titleScreenBG.png"]];
        [self addSubview:background];
        
        int margin = 30;
        frame.size.height = frame.size.height/6;
        frame.size.width -= 2*margin;
        frame.origin.x += margin;
        frame.origin.y += 3*margin;
        
        self.messageTextView = [[UITextView alloc] initWithFrame:frame];
        self.messageTextView.textAlignment = NSTextAlignmentCenter;
        [self.messageTextView setEditable:NO];
        [self.messageTextView setBackgroundColor:[UIColor clearColor]];
        [self addSubview:self.messageTextView];

        
        //animation - activity indicator
        NSArray *imageNames = @[@"running1.png", @"running2.png", @"running3.png", @"running4.png",
                                @"running5.png", @"running6.png", @"running7.png"];
        NSMutableArray *images = [[NSMutableArray alloc] init];
        for (int i = 0; i < imageNames.count; i++) {
            [images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
        }
        CGRect frameImageView = CGRectMake((frame.size.height*6)/2+40,frame.size.height+3*margin,80,80);
        self.loadingImageView = [[UIImageView alloc] initWithFrame:frameImageView];
        
        [self addSubview:self.loadingImageView];
        

        self.loadingImageView.animationImages = images;
        self.loadingImageView.animationDuration = 0.5;
        [self.loadingImageView startAnimating];
    
        //quit button
        CGRect frameButton = CGRectMake(frameImageView.origin.x, frameImageView.origin.y+frameImageView.size.height, 80, 80);
        self.quitButton = [[UIButton alloc] initWithFrame:frameButton];
        [self.quitButton setTitle:@"Quit" forState:UIControlStateNormal];
        [self.quitButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self addSubview:self.quitButton];
        

    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
